package com.anyou.mall.use.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.anyou.common.core.domain.AjaxResult;
import com.anyou.common.core.domain.entity.SysUser;
import com.anyou.common.exception.ServiceException;
import com.anyou.mall.use.domain.UserNotice;
import com.anyou.mall.use.param.NoticeParam;
import com.anyou.mall.use.service.IUserNoticeService;
import com.anyou.system.service.ISysUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.use.domain.UserSystemNotice;
import com.anyou.mall.use.service.IUserSystemNoticeService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 用户消息Controller
 *
 * @author gaochaohao
 * @date 2022-04-22
 */
@Api(tags = "用户消息")
@RestController
@RequestMapping("/use/userSystemNotice")
public class UserSystemNoticeController extends BaseController
{
    @Autowired
    private IUserSystemNoticeService userSystemNoticeService;
    @Autowired
    private IUserNoticeService userNoticeService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询用户消息列表
     */
    @ApiOperation("查询用户消息列表")
    @PreAuthorize("@ss.hasPermi('use:userSystemNotice:list')")
    @GetMapping("/list")
    public TableDataInfo<List<UserNotice>> list(@Valid NoticeParam param)
    {
        startPage();
        List<UserNotice> list=userNoticeService.getAdminNoticeList(param);

        return getDataTable(list);
    }

    /**
     * 导出用户消息列表
     */
    @ApiOperation("导出用户消息列表")
    @PreAuthorize("@ss.hasPermi('use:userSystemNotice:export')")
    @Log(title = "用户消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserSystemNotice userSystemNotice)
    {
        List<UserSystemNotice> list = userSystemNoticeService.selectUserSystemNoticeList(userSystemNotice);
        ExcelUtil<UserSystemNotice> util = new ExcelUtil<UserSystemNotice>(UserSystemNotice.class);
        util.exportExcel(response, list, "用户消息数据");
    }

    /**
     * 获取用户消息详细信息
     */
    @ApiOperation("获取用户消息详细信息")
    @PreAuthorize("@ss.hasPermi('use:userSystemNotice:query')")
    @GetMapping(value = "/{systemNoticeId}")
    public ApiResult<UserSystemNotice> getInfo(@PathVariable("systemNoticeId") Long systemNoticeId)
    {
        return ApiResult.success(userSystemNoticeService.selectUserSystemNoticeBySystemNoticeId(systemNoticeId));
    }

    /**
     * 新增用户消息
     */
    @ApiOperation("新增用户消息")
    @PreAuthorize("@ss.hasPermi('use:userSystemNotice:add')")
    @Log(title = "用户消息", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody UserSystemNotice userSystemNotice)
    {
        return ApiResult.success(userSystemNoticeService.insertUserSystemNotice(userSystemNotice));
    }

    /**
     * 修改用户消息
     */
    @ApiOperation("修改用户消息")
    @PreAuthorize("@ss.hasPermi('use:userSystemNotice:edit')")
    @Log(title = "用户消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody UserSystemNotice userSystemNotice)
    {
        return ApiResult.success(userSystemNoticeService.updateUserSystemNotice(userSystemNotice));
    }

    /**
     * 删除用户消息
     */
    @ApiOperation("删除用户消息")
    @PreAuthorize("@ss.hasPermi('use:userSystemNotice:remove')")
    @Log(title = "用户消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{systemNoticeIds}")
    public ApiResult remove(@PathVariable Long[] systemNoticeIds)
    {
        return ApiResult.success(userSystemNoticeService.deleteUserSystemNoticeBySystemNoticeIds(systemNoticeIds));
    }
}
